var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    overlayShow: false,
    allDataList: {},
    order_id: "",
    inShow: false,
    newBlindBoxData: {}, //立即开箱数据
    info: false
  },
  onShow: function () {
    this.setData({
      info: true
    })
  },
  onHide: function () {
    this.setData({
      info: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      order_id: options.order_id
    })
    this.getData();
  },
  // 获取数据
  getData() {
    app._postNetWork({
      url: app.getNetAddresss('plugin.new-blind-box.frontend.activity.open-box-page'),
      data: { order_id: this.data.order_id },
      success: ({data}) => {
        if(data.result) {
          let newObj = {
            list: [{...data.data.activity,goods: data.data.goods}],
            ...data.data
          }
          this.setData({
            allDataList: newObj,
            inShow: true
          })
        }else {
          wx.showToast({
            icon: 'none',
            title: data.msg,
            duration: 1500
          });
          // 跳转到盲盒
          wx.navigateTo({
            url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=newBindBox&title="+'我的盲盒',
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    })
  },
  
  // 立即开箱
  clickUnpack() {
    let newObj = {
      api: 'plugin.new-blind-box.frontend.activity.open-box',
      order_id: this.data.order_id
    }
    this.setData({
      newBlindBoxData: newObj,
      overlayShow: true
    })
  },
  // 关闭
  issueGoodsClose(value) {
    this.setData({
      overlayShow: false
    })
  },
})